//
//  PrivacyOfUserDetailsVC.m
//  Ginix
//
//  Created by ff on 2025/3/24.
//

#import "PrivacyOfUserDetailsVC.h"
#import <WebKit/WebKit.h>

@interface PrivacyOfUserDetailsVC ()<WKNavigationDelegate,WKUIDelegate>
@property (nonatomic,strong) WKWebView * detailsView;

@end

@implementation PrivacyOfUserDetailsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setSubViewLayout];
}

-(void)setSubViewLayout{
    
    [self.view addSubview:self.detailsView];
    [_detailsView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(NavHeight + 10 * FMScaleX, 0, 0, 0));
    }];
    NSString * url = @"";
    if(self.type == userType){
        url = @"https://www.ginix.cn/user/index.html";
        self.title = @"用户协议";
    }else {
        url = @"https://www.ginix.cn/privacy/index.html";
        self.title = @"隐私政策";
    }
    [self.detailsView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}

-(WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
{
    if (!navigationAction.targetFrame.isMainFrame) {
        [webView loadRequest:navigationAction.request];
    }
    return nil;
}

-(WKWebView *)detailsView{
    
    if (!_detailsView) {
        WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
        NSString *jSString = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);";
        WKUserScript *script = [[WKUserScript alloc] initWithSource:jSString injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
        [wkWebConfig.userContentController addUserScript:script];
        
        _detailsView = [[WKWebView alloc]initWithFrame:CGRectZero configuration:wkWebConfig];
        _detailsView.opaque = NO;
        _detailsView.backgroundColor = UIColor.whiteColor;
        _detailsView.scrollView.backgroundColor = UIColor.whiteColor;
        _detailsView.UIDelegate = self;
  
    }
    return _detailsView;
}


@end
